<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>

<body>
  <input id="input" type="file">
  <img id="img" style="width: 500px;" src="" alt="">
</body>
<script>
  const file = document.getElementById("input");
  const img = document.getElementById('img')
  file.addEventListener('change', function () {
    console.log(this.files);
    const reader = new FileReader();
    reader.readAsDataURL(this.files[0], "UTF-8");
    reader.onload = (res) => {
      console.log('reader.onload', res);
      img.src = res.target.result;
      try {
        console.log(img);
        img.addEventListener('load', function () {
          console.log(img.width);
        })
        img.addEventListener('error', function (err) {
          console.log('error', err);
        })
      } catch (error) {
        console.log(error);
      }
    }
  })
</script>

</html>